
package com.smfx.yxt.excel.tags;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import com.smfx.yxt.excel.ExcelParser;


/**
 * <b>FormulaTag</b> is a class which can output excel formula
 * 
 */
public class FormulaTag implements ITag {

	public static final String KEY_FORMULA = "#formula";

	public int[] parseTag(HSSFSheet sheet, HSSFRow curRow, HSSFCell curCell) {

		String cellstr = curCell.getRichStringCellValue().getString();
		if (null == cellstr || "".equals(cellstr)) {
			return new int[] { 0, 0, 0 };
		}

		cellstr = cellstr.substring(KEY_FORMULA.length()).trim();

		Object formula = ExcelParser.parseExpr(cellstr);

		if (null != formula) {
			curCell.setCellFormula(formula.toString());
		}

		return new int[] { 0, 0, 0 };
	}

	public boolean hasEndTag() {
		return false;
	}

	public String getTagName() {
		return KEY_FORMULA;
	}

}
